{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
    <h3 class="pb-3">新增固定资产</h3>
    <table class="layui-table layui-table-form">
        {if condition="$eid gt 0"}
        <input type="hidden" name="eid" value="{$eid}" lay-verify="required">
        {else/}
        <tr>
            <td class="layui-td-gray">所在企业<font>*</font></td>
            <td colspan="5">
                <select name="eid" lay-verify="required" lay-reqText="请选择所属企业" lay-filter="asyncEidSelect"
                        id="async-eid-select">
                    <option value="0">系统管理员</option>
                    {volist name="enterprise" id="v"}
                    <option value="{$v.id}" {notempty name="$detail.eid" } {eq name="$v.id" value="$detail.eid" }
                            selected{/eq}{/notempty}>{$v.title}</option>
                    {/volist}
                </select>
            </td>
        </tr>
        {/if}
        <tr>
            <td class="layui-td-gray">固定资产名称<font>*</font>
            </td>
            <td><input type="text" name="name" lay-verify="required" {notempty name="$detail.name"
                    }value="{$detail.name}" {/notempty} lay-reqText="请输入固定资产名称" autocomplete="off" placeholder="请输入固定资产名称"
                    class="layui-input"></td>
            <td class="layui-td-gray">所在部门<font>*</font>
            </td>
            <td>
                <select name="did" lay-verify="required" lay-reqText="请选择所属部门" lay-filter="asyncDidSelect"
                    id="async-did-select">
                    <option value="">请选择所属部门</option>
                    {volist name="department" id="v"}
                    <option value="{$v.id}" {notempty name="$detail.did" } {eq name="$v.id" value="$detail.did" }
                        selected{/eq}{/notempty}>{$v.title}</option>
                    {/volist}
                </select>
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">固定资产编码<font>*</font>
            </td>
            <td>
                <input type="text" name="code" lay-verify="required" {notempty name="$detail.code"
                    }value="{$detail.code}" {/notempty} lay-reqText="请输入固定资产编码" autocomplete="off" placeholder="请输入固定资产编码"
                    class="layui-input">
            </td>
            </td>
            <td class="layui-td-gray">数量<font>*</font>
            </td>
            <td>
                <input type="text" name="num" lay-verify="required" {notempty name="$detail.num" }value="{$detail.num}"
                    {/notempty} lay-reqText="请输入固定资产数量" autocomplete="off" placeholder="请输入固定资产数量" class="layui-input">
            </td>
            </td>
        </tr>

        <tr>
            <td class="layui-td-gray">购入时间<font>*</font>
            </td>
            <td>
                <input id="in_time" name="in_time" autocomplete="off" {notempty name="$detail.fmt_in_time"
                    }value="{$detail.fmt_in_time}" {/notempty} class="layui-input" value="" readonly
                    lay-verify="required" placeholder="请选择购入时间" lay-reqText="请选择开始时间">
            </td>
            <td class="layui-td-gray">到期日<font>*</font>
            </td>
            <td>
                <input id="out_time" name="out_time" autocomplete="off" class="layui-input" {notempty
                    name="$detail.fmt_out_time" }value="{$detail.fmt_out_time}" {/notempty} readonly
                    lay-verify="required" placeholder="请选择到期日" lay-reqText="请选择结束时间">
            </td>
        </tr>

        <tr>
            <td class="layui-td-gray">原值(元)<font>*</font>
            </td>
            <td>
                <input type="number" name="original_value" lay-verify="required" {notempty name="$detail.original_value"
                    }value="{$detail.original_value}" {/notempty} lay-reqText="请输入固定资产原值" autocomplete="off"
                    placeholder="请输入固定资产原值" class="layui-input">
            </td>
            </td>
            <td class="layui-td-gray">残值率(%)<font>*</font>
            </td>
            <td>
                <input type="number" name="loss_rate" lay-verify="required" {notempty name="$detail.loss_rate"
                    }value="{$detail.loss_rate}" {/notempty} lay-reqText="请输入固定资产残值率" autocomplete="off"
                    placeholder="请输入固定资产残值率" class="layui-input">
            </td>
            </td>
        </tr>

        <tr>
            <td class="layui-td-gray">折旧期间<font>*</font>
            </td>
            <td>
                <input type="num" name="period" lay-verify="required" {notempty name="$detail.period"
                       }value="{$detail.period}" {/notempty} lay-reqText="请输入固定资产原值" autocomplete="off"
                placeholder="请输入固定资产折旧期间" class="layui-input">
            </td>
            </td>
        </tr>

        <input type="hidden" name="id" , {notempty name="$detail.id" }value="{$detail.id}" {/notempty}>
    </table>
    <div class="py-3">
        <input type="hidden" name="scene" value="add">
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool', 'employeepicker'];
    function gouguInit() {
        var form = layui.form, tool = layui.tool, employeepicker = layui.employeepicker;
        // 监听选择框的选择变化（如果有需要）
        form.on('select(asyncEidSelect)', function (data) {
            $.getJSON('/home/equipment/getEnterpirseDepartment?eid=' + data.value, function (res) {


                var html = '';
                layui.each(res.data, function (index, item) {
                    html += '<option value="' + item.pid + '">' + item.title + '</option>';
                });
                document.getElementById('async-did-select').innerHTML = html;
                form.render($('#async-did-select')); // 重新渲染select
                // 模拟数据输出

                console.log(res); // 被选中的值
            });
        });

        //监听提交
        form.on('submit(webform)', function (data) {
            let callback = function (e) {
                layer.msg(e.msg);
                if (e.code == 0) {
                    tool.sideClose(1000);
                }
            }
            tool.post("/home/equipment/add", data.field, callback);
            return false;
        });

        var form = layui.form,
            tool = layui.tool,
            oaTool = layui.oaTool,
            laydate = layui.laydate;
        //日期时间范围
        laydate.render({
            elem: '#in_time',
            type: 'date',
            format: 'yyyy-MM-dd',
            showBottom: false
        });
        //日期时间范围
        laydate.render({
            elem: '#out_time',
            type: 'date',
            format: 'yyyy-MM-dd',
            showBottom: false
        });

    }
</script>
{/block}
<!-- /脚本 -->